﻿
var mEvidenceOverDueSeizureReportQuery = {};

//var mDeadlineSystemPar = {};

$(function () {


    var args = getUrlArgs();
    mEvidenceOverDueSeizureReportQuery.ModelType = parseInt(args["modeType"]);

    $("#cmbTransferDept").combobox({
        valueField: 'Id',
        textField: 'Name',
        editable: false,
        panelHeight: 200,
        onSelect: function (record) { mEvidenceOverDueSeizureReportQuery.TransferDeptId = record.Id; }
    });

    $("#cmbManageDept").combobox({
        valueField: 'Id',
        textField: 'Name',
        editable: false,
        panelHeight: 200,
        onSelect: function (record) { mEvidenceOverDueSeizureReportQuery.ManageDeptId = record.Id; }
    });

    gLoadAllDepts(function (orgs) {
        var allOrg = {};
        allOrg.Id = 0;
        allOrg.Name = "全部";
        orgs.splice(0, 0, allOrg);
        $('#cmbTransferDept').combobox('loadData', orgs);
        $('#cmbManageDept').combobox('loadData', orgs);
    }, false);

    loadOverDueSystemPar();

    packQuery();//打包初始查询条件

    $('#overDueReportGrid').datagrid({
        url: '/Report/LoadEvidenceOverDueSeizureReport',
        fitColumns: true,
        rownumbers: true,
        resizable: true,
        pagination: true,
        pageNumber: 1,
        pageSize: 20,
        nowrap: false,
        height: 540,
        idField: 'Id',
        toolbar: '#overDueReportBar',
        queryParams: { 'evidenceOverDueSeizureReportQuery': JSON.stringify(mEvidenceOverDueSeizureReportQuery) },
        singleSelect: true,
        onDblClickRow: selStockRow,
        columns: [[
               { title: 'Id', field: 'EvidenceId', align: 'center', width: 0, hidden: true },
               { title: '超期时间', field: 'OverDay', align: 'center', width: 70, formatter: formateOverDue },
               { title: '还剩时间', field: 'MindDay', align: 'center', width: 70, formatter: formateMindDay },
               { title: '办案单位', field: 'TDeptName', align: 'left', width: 80, formatter: gFormatDeptName },
               { title: '案件编号', field: 'CaseNo', align: 'left', width: 70 },
               { title: '案件类型', field: 'CaseTypeName', align: 'left', width: 60 },
               { title: '物品分类', field: 'EvidenceTypeName', align: 'left', width: 80 },
               { title: '物品名称', field: 'EvidenceName', align: 'left', width: 80 },
               { title: '规格型号', field: 'EvidenceModel', align: 'left', width: 80 },
               { title: '计量单位', field: 'UMName', align: 'center', width: 40 },
               { title: '未入库数量', field: 'EQty', align: 'right', width: 60, formatter: formatUnOutStockQty },
               { title: '提交时间', field: 'CheckTime', align: 'center', width: 80, formatter: getFormatDate },
               { title: '扣押天数', field: 'SeizureDay', align: 'right', width: 50 },
               { title: '保管单位', field: 'MDeptName', align: 'left', width: 80, formatter: gFormatDeptName }

        ]],
        rowStyler: function (index, row) {
            if (row.OverDay < 1) {
                return 'color:#ffff00;';
            } else {
                return 'color:#ff0000;';
            }
        }
    });

    if (mEvidenceOverDueSeizureReportQuery.ModelType == 0)
        $('#overDueReportGrid').datagrid('hideColumn', 'MindDay');
    else if (mEvidenceOverDueSeizureReportQuery.ModelType == 1)
        $('#overDueReportGrid').datagrid('hideColumn', 'OverDay');
    else
        $.messager.alert('提示', '报表类型错误');

});

function loadOverDueSystemPar() {
    $.ajax({
        url: "/System/LoadSystemParameterList",
        type: "POST",
        async: false,
        dataType: "json",
        //data: { "systemParameterKey": "InStockDeadline"},
        success: function (req) {
            if (req.IsSuccess) {
                var ls = JSON.parse(req.Data);

                var count = ls.length;

                for (var i = 0; i < count; i++) {
                    var d = ls[i];
                    if (d.FKey == 'OutStockDeadline')
                        mEvidenceOverDueSeizureReportQuery.Deadline = parseInt(d.Value);
                    else if (d.FKey == 'OutStockMind')
                        mEvidenceOverDueSeizureReportQuery.CloseToExpire = parseInt(d.Value);

                }
            } else {
                $.messager.alert('提示', req.Data);
            }
        },
    });
}

function getFormatDate(value, rowData, index) {
    if (value) {
        return gFormatDateFormCSharp(value, 'yyyy-MM-dd');
    }
}

function formateMindDay(value, rowData, index) {
    if (value < 1) {
        return "小于1天";
    } else {
        var day = parseInt(value);
        return day + "天";
    }
}



function formatUnOutStockQty(value, rowData, index) {
    return rowData.EQty - rowData.EOutStockQty;
}

function formateOverDue(value, rowData, index) {
    if (value < 1) {
        return "小于1天";
    } else {
        var day = parseInt(value);
        return day + "天";
    }
}

function selStockRow(rowIndex, rowData) {

}

function packQuery() {
    //mEvidenceDeadlineReportQuery.Deadline = parseInt(mDeadlineSystemPar.Value);
}


function searchOverDueAction() {
    var json = JSON.stringify(mEvidenceOverDueSeizureReportQuery);
    $('#overDueReportGrid').datagrid('reload', { 'evidenceOverDueSeizureReportQuery': json });
}
